package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.ProductPicture;

/**
 * Session Bean implementation class EaoProductPicture
 */
@Stateless(mappedName = "eaoProductPicture")
@LocalBean
public class EaoProductPicture {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoProductPicture() {
        // TODO Auto-generated constructor stub
    }
    

    public ProductPicture find(int id) {
        return em.find(ProductPicture.class, id);
    }

    public List<ProductPicture> list() {
    	return em.createQuery("SELECT pp FROM ProductPicture pp", ProductPicture.class).getResultList();
    }

    public void create(ProductPicture productPicture) throws Exception {
        try{
        	em.persist(productPicture);
        	em.flush();
        }catch (Exception e) {
        	throw new Exception(e.getMessage());
		}
    }

    public void update(ProductPicture productPicture) {
        em.merge(productPicture);
    }

    public void delete(ProductPicture productPicture) {
        em.remove(em.contains(productPicture) ? productPicture : em.merge(productPicture));
    }

}
